package logic

import (
	"context"
	"week2/user_srv/model/redis"

	"week2/user_srv/internal/svc"
	"week2/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsCodeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsCodeLogic {
	return &SendSmsCodeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsCodeLogic) SendSmsCode(in *user.SendSmsCodeRequest) (*user.SmsCodeResponse, error) {
	// todo: 发送短信验证

	err := redis.RedisSetSmsCode(in.Mobile, in.Code, in.Source)
	if err != nil {
		logx.Error("缓存短信写入失败", err)
		return nil, err
	}

	return &user.SmsCodeResponse{}, nil
}
